const background = 'background';
chrome.runtime.onMessage.addListener(
    function (message, sender, sendResponse) {
        if (message.type == 'options') {
            console.log('options:::', message.value);
            chrome.storage.local.set({ options: message.value }, function () {
                console.log("保存成功");
                //@ts-ignore
                chrome.notifications.create(null, {
                    type: 'basic',
                    iconUrl: 'img/icon.png',
                    title: '保存',
                    message: '保存成功'
                });
            });

            sendResponse({ tabId: sender.tab?.id });

        }
        if (message.type === 'getTabId') {
            sendResponse({ tabId: sender.tab?.id });

        }
        console.log('message', message);
        if (message.type === 'hasTicket') {
            console.log('has a ticket~  come on');
                //@ts-ignore

            chrome.notifications.create(null, {
                type: 'basic',
                iconUrl: 'img/icon.png',
                title: '标题1',
                message: '应用完毕。。。。'//你选的航班有票啦~ 快买买买
            });
            // sendResponse({ tabId: sender.tab.id });

        }
    }
);

chrome.webRequest.onBeforeSendHeaders.addListener(
    function (details) {
        console.log('details', details);
    },
    {
        urls: ["*://*/*doRecommendSearch.shtml"],
    }, ["blocking", "requestHeaders"]
);
chrome.webRequest.onBeforeRequest.addListener(
    function (details) {
        console.log('details cancel', details);
        return { cancel: true }
    },
    {
        urls: ["*://*/*gio.js"],
    }, ["blocking"]
);
console.log('background....,');